package com.srwl.mytx.fragment;

import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.Toast;

import androidx.fragment.app.DialogFragment;

import com.google.android.material.snackbar.Snackbar;
import com.srwl.easeui.widget.MyTitleBar;
import com.srwl.mytx.R;

public class BaseFragment extends DialogFragment  {
    protected MyTitleBar titleBar;
    protected InputMethodManager inputMethodManager;
    protected float density;
    protected int screenWidth;
    protected int screenHeight;
    protected Context mContext;

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        inputMethodManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
        titleBar = getView().findViewById(R.id.title_bar);
        density = getResources().getDisplayMetrics().density;
        screenWidth = getResources().getDisplayMetrics().widthPixels;
        screenHeight = getResources().getDisplayMetrics().heightPixels;
        mContext = getActivity();
    }


    protected void hideSoftKeyboard() {
        if (getActivity().getWindow().getAttributes().softInputMode != WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN) {
            if (getActivity().getCurrentFocus() != null)
                inputMethodManager.hideSoftInputFromWindow(getActivity().getCurrentFocus().getWindowToken(),
                        InputMethodManager.HIDE_NOT_ALWAYS);
        }
    }

    protected void showToast(final String toastContent) {
        showToast(getActivity().getWindow().getDecorView(), toastContent);
    }

    protected void showToast(final View view, final String toastContent) {
        Snackbar.make(view, toastContent, Snackbar.LENGTH_LONG).show();

    }

    protected void showToast_v1(String showString) {
        Toast.makeText(getActivity(), showString, Toast.LENGTH_SHORT).show();
    }

}
